<template>
  <a-tooltip placement="top">
    <template slot="title">
      <span>{{value}}</span>
    </template>
    <div v-if="width" class="text-overflow" :style="{width:width}">
      {{value}}
    </div>
    <div v-else-if="value && limitLines && limitLines > 1">
      <div v-for="(item, index) in (limitLines - 1)" :key="index">{{ value.slice(index * lineWords, (index + 1) * lineWords) }}</div>
      <div>{{ value.slice((limitLines - 1) * lineWords) | ellipsis(lineWords) }}</div>
    </div>
    <span v-else>{{ value | ellipsis(length) }}</span>
  </a-tooltip>
</template>

<script>
  export default {
    name: 'JEllipsis',
    props: {
      value: {
        type: String,
        required: false,
      },
      length: {
        type: Number,
        required: false,
        default: 25,
      },
      width:{
        type:String
      },
      limitLines: {
        type: Number,
        required: false,
      }
    },
    computed: {
      lineWords(){
        return Math.floor(this.length / this.limitLines);
      }
    }
  }
</script>

<style lang="less" scoped>
.text-overflow{
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
  text-align: left;
}
</style>
